package com.yms.spring.bean;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @version : 1.0
 * @author: yangmingsong
 * @date: 2022/8/14-08-14-20:24
 * @description: spring5-test
 */
public class SpringUtil implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    @Override
    public  void setApplicationContext(ApplicationContext a) throws BeansException {
        setContext(a);
    }
    public static void setContext(ApplicationContext a){
        applicationContext = a;
    }

    public static  <T> T getBean(Class<T> c){
        return applicationContext.getBean(c);
    }
}
